﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Training9
{
    public partial class frmCourseSel : Form
    {
        public frmCourseSel()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            SqlOperate obj = new SqlOperate();
            string strSql = "select courseID,courseName,courseType,notes from T_Course where courseID like '%" + textBox1.Text + "%'";
            SqlDataReader odr = obj.GetDR(strSql);
            while (odr.Read())
            {

                DataGridViewRow row = new DataGridViewRow();
                int index = dataGridView1.Rows.Add(row);
                dataGridView1.Rows[index].Cells[0].Value = odr.GetValue(0).ToString();
                dataGridView1.Rows[index].Cells[1].Value = odr.GetValue(1).ToString();
                dataGridView1.Rows[index].Cells[2].Value = odr.GetValue(2).ToString();
                dataGridView1.Rows[index].Cells[3].Value = odr.GetValue(3).ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            SqlOperate obj = new SqlOperate();
            string strSql = "select courseID,courseName,courseType,notes from T_Course ";
            SqlDataReader odr = obj.GetDR(strSql);
            while (odr.Read())
            {

                DataGridViewRow row = new DataGridViewRow();
                int index = dataGridView1.Rows.Add(row);
                dataGridView1.Rows[index].Cells[0].Value = odr.GetValue(0).ToString();
                dataGridView1.Rows[index].Cells[1].Value = odr.GetValue(1).ToString();
                dataGridView1.Rows[index].Cells[2].Value = odr.GetValue(2).ToString();
                dataGridView1.Rows[index].Cells[3].Value = odr.GetValue(3).ToString();
            }
        }
    }
}
